import * as types from './mutation-types'

export const initData = ({commit}, params) => {

  commit(types.INITDATA, params)

}
export const initUserData = ({commit}, params) => {
  commit(types.INITUSERDATA, params)
}
export const changeUserData = ({commit}, params) => {
  commit(types.CHANGEUSERDATA, params)
}

export const alert = ({commit}, payload) => {
  commit(types.ALERT, payload)
}
export const replaceTemplate = ({commit}, params) => {
  // debugger
  commit(types.REPLACETEMPLATE, params)
}

export const changeRightTab = ({commit}, params) => {
  // debugger
  commit(types.CHANGERIGHTFUNCTAB, params)
}

export const selectItem = ({commit}, index, multi) => {
  commit(types.SELECTITEM, index, multi)
}

export const delItem = ({commit}) => {
  commit(types.DELITEM)

}

export const clearCheckedItems = ({commit}, index, multi) => {
  commit(types.CLEARCHECKEDITEMS, index, multi)
}

export const setStyleTwo = ({commit}, params) => {
  commit(types.SETSTYLETWO, params)
};
export const setStyle = ({commit}, params) => {
  commit(types.SETSTYLE, params)
};

export const setAnimStyle = ({commit}, params, isIn) => {
  commit(types.SETANIMSTYLE, params, isIn)
};

export const changeTextStyle = ({commit}, params) => {
  // debugger
  commit(types.CHANGETEXTSTYLE, params)
}
export const changePicStyle = ({commit}, params) => {
  // debugger
  commit(types.CHANGEPICSTYLE, params)
}
export const changeText = ({commit}, obj) => {
  commit(types.CHANGETEXT, obj)
}
export const dragPage = ({commit}, obj) => {
  commit(types.DRAGPAGE, obj)
}
export const confirm = ({commit}, payload) => {
  commit(types.CONFIRM, payload)
};

export const hideConfirm = ({commit}, payload) => {
  commit(types.HIDECONFIRM, payload)
};

export const addClass = ({commit}, payload) => {
  commit(types.ADDCLASS, payload)
};

export const removeClass = ({commit}, payload) => {
  commit(types.REMOVECALSS, payload)
};

export const addText = ({commit},payload) => {
  commit(types.ADDTEXT,payload)
}

export const selectPage = ({commit, state}, index) => {
  commit(types.SELECTPAGE, index)
};

export const addPage = ({commit}, params) => {
  // debugger
  commit(types.ADDPAGE, params)
};

export const copyPage = ({commit}, params) => {
  commit(types.COPYPAGE, params)
};

export const delPage = ({commit, state}, index) => {
  if (state.workData.pages.length === 1) {
    commit(types.ALERT, {
      show: true,
      msg: '至少保留一页',
      type: 'warning'
    });
    setTimeout(function () {
      commit(types.HIDEALERT);
    }, 2500);
    return;
  }
  commit(types.DELPAGE, index)
};

export const pushHistory = ({commit}, params) => {

  commit(types.PUTHISTORY, params)
};

export const updateCurrentdata = ({commit}, params) => {

  commit(types.UPDATECURRENTDATA, params)
};
export const test = ({commit}, params) => {
  // debugger
  commit(types.TEST, params)
};
export const addSysFile = ({commit}, params) => {
  //debugger
  commit(types.ADDSYSFILE, params)
};
export const reload = ({commit, state}) => {

  var result = [];
  var items = state.workData.pages[state.currentPage - 1].elements;

  for (var i = 0; i < items.length; i++) {
    if (items[i] !== undefined) {
      result.push(items[i]);
    }
  }

  commit(types.CLEARCURRENTPAGE)

  setTimeout(function () {
    commit(types.RELOAD, result)
  }, 1);

};

//修改图片或者背景
export const addPicOrBg = ({commit}, params) => {
  commit(types.ADDPICORBG, params)
};
//修改场景信息
export const changeSceneInfo = ({commit}, params) => {
  commit(types.CHANGESCENEINFO, params)
};

//修改动画属性
export const changeAni = ({commit}, params) => {
  commit(types.CHANGEANI, params)
};


// 预览动画
export const reviewAni = ({commit, state}, params) => {

  var result = [];
  var anim = state.workData.pages[state.currentPage - 1].elements[state.checkedItems[0]].anim;
  if (anim.length == 0) {

    return
  }

  for (var i = 0; i < anim.length; i++) {
    result.push(anim[i]);

  }
  commit(types.CLEARANI)

  var params = {};
  params.type = "review";
  params.anim = result;

  setTimeout(function () {
    commit(types.CHANGEANI, params)
  }, 1);

};


//修改form
export const changeForm = ({commit}, params) => {
  commit(types.CHANGEFORM, params)
};

//倒计时
export const addCountDown = ({commit}, params) => {
  commit(types.ADDCOUNTDOWN, params)
}
//添加组件
export const addComponent = ({commit}, params) => {
  // debugger
  commit(types.ADDCOMPOENT, params)
}

export const changePhoneButton = ({commit}, params) => {
  // debugger
  commit(types.CHANGEPHONEBUTTON, params)
}
export const changeDeadLineTime = ({commit}, params) => {

  commit(types.CHANGDEADLINETIME, params)
}


export const copySelectItem = ({commit}) => {

  commit(types.COPYSELECTITEM)
}
export const pasteItem = ({commit}) => {

  commit(types.PASTEITEM)
}
export const upSelectItem = ({commit}) => {

  commit(types.UPSELECTITEM)
}

export const downSelectItem = ({commit}) => {
  commit(types.DOWNITEM)
}
export const stickieSelectItem = ({commit}) => {

  commit(types.STICKIESELECTITEM)
}
export const bottomSelectItem = ({commit}) => {

  commit(types.BOTTOMSELECTITEM)
}

export const initSvgColorList = ({commit}, params) => {
  // debugger
  commit(types.INITSVGCOLORLIST, params)
}


export const changeSvgColorList = ({commit}, params) => {
  // debugger
  commit(types.CHANGESVGCOLORLIST, params)
}

export const processData = ({commit}, params) => {
  commit(types.PROCESSDATA, params)
}
export const checkScenesData = ({commit}, params) => {
  commit(types.CHECKSCENCESDATA, params)
}
